package ch.usi.inf.pf2.editor;

import ch.usi.inf.pf2.Sheet;

/**
 * Defines the possibles actions that the user can do, undo or redo
 * 
 * @author Lorenzo Baracchi
 *	
 */
public abstract class Action 
{	
	protected Sheet sheet;
	private int rowIndex;
	private int columnIndex;
	
	/**
	 * Create an action with the given row and column index
	 * @param Sheet
	 * @param rowIndex the row index
	 * @param columnIndex the column index
	 */
	public Action (Sheet sheet, int rowIndex, int columnIndex)
	{
		this.sheet =sheet;
		this.rowIndex=rowIndex;
		this.columnIndex=columnIndex;
	}
	
	/**
	 * Create the default action that doesn't do anything :P
	 */
	public Action ()
	{
		this.rowIndex=-1;
		this.columnIndex=-1;
	}
	
	/**
	 * Return the row index of the Action done
	 * @return the index
	 */
	public int getRowIndex ()
	{
		return this.rowIndex;
	}
	
	/**
	 * Return the column index of the Action done
	 * @return
	 */
	public int getColumnIndex ()
	{
		return this.columnIndex;
	}
	
	/**
	 * Set the row index of the action done
	 * @param rowIndex the index
	 */
	void setRowIndex (int rowIndex)
	{
		this.rowIndex=rowIndex;
	}
	
	/**
	 * Set the column index of the action done
	 * @param columnIndex the index
	 */
	void setColumnIndex (int columnIndex)
	{
		this.columnIndex=columnIndex;
	}
	
	/**
	 * Return if the two are equals
	 */
	public boolean equals (Object o)
	{
		if(o instanceof Action)
			return (rowIndex==((Action)o).rowIndex)&&(columnIndex==((Action)o).columnIndex);
		else
			return false;
	}
	
	public abstract void evaluate ();
	
	public abstract void restore ();
}
